package com.fywsy.fyweb.strategy;

import com.fywsy.fyweb.entity.SendItem;
import com.fywsy.fyweb.utils.RestTemplateUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

/**
 * 天之禁-永恒仙域
 *
 * 游戏后台实现类
 * 注解gameId对应数据库游戏id
 * 注解GongnengMethod对应数据库功能id
 */
@Component
@GameId(80)
public class TianzhijinGameStrategy extends BaseGameStrategy {
    public static final String QUERY = "http://114.66.45.140:30481/gmhtss/user/apiquery.php";

    public static final String SEND = "http://114.66.45.140:30481/gmhtss/user/gmquery.php";

    public static final String DELITEM = "http://114.66.45.140:30481/gmhtss/user/delItem.php";

    public static final String CLEARMAIL = "http://114.66.45.140:30481/gmhtss/user/clearMail.php";


    public String quertUid(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("checknum", "diyao88");
        params.add("typea", "user_lyzwlkj_vip");
        params.add("qu", "1001");

        params.add("uid", item.uid);

        return RestTemplateUtil.sendPostForm(QUERY, params);
    }

    /**
     * type=charge&checknum=diyao88&userid=%E9%A3%8E%E4%BA%91%2C281871601550706381%2C844540079886237697&num=11223&qu=1001
     * {"errcode":0,"info":"\u5145\u503c\u6210\u529f!!"}
     * @param item
     * @return
     */
    @GongnengMethod(8001)
    public String pay(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("checknum", "diyao88");
        params.add("type", "charge");
        params.add("qu", "1001");

        params.add("userid", quertUid(item));
        params.add("num", item.number);

        return RestTemplateUtil.sendPostFormAndGetJsonKey(SEND, params,"info");
    }

    /**
     * type=mail&checknum=diyao88&userid=%E9%A3%8E%E4%BA%91%2C281871601550706381%2C844540079886237697&item=3&num=112233&qu=1001
     *
     * @param item
     * @return
     */
    @GongnengMethod(8002)
    public String mail(SendItem item) {
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("checknum", "diyao88");
        params.add("type", "mail");
        params.add("qu", "1001");

        params.add("userid", quertUid(item));
        params.add("num", item.number);
        params.add("item", item.itemId);

        return RestTemplateUtil.sendPostFormAndGetJsonKey(SEND, params,"info");
    }





    @GongnengMethod(8003)
    public String delItem(SendItem item) {
        String uid = quertUid(item);
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("uid", uid.split(",")[1]);
        params.add("qufu", "1001");
        params.add("number", item.number);
        params.add("itemId", item.itemId);

        return RestTemplateUtil.sendPostFormAndGetJsonKey(DELITEM, params,"info");
    }


    @GongnengMethod(8004)
    public String clearMail(SendItem item) {
        String uid = quertUid(item);
        MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
        params.add("uid", uid.split(",")[1]);
        params.add("qufu", "1001");

        return RestTemplateUtil.sendPostFormAndGetJsonKey(CLEARMAIL, params,"info");
    }

    public static void main(String[] args) {
        SendItem item = new SendItem();
        item.uid = "风云";
        item.qufu = "1001";
        item.number = "137";
        item.itemId = "18001";
        System.out.println(new TianzhijinGameStrategy().delItem(item));
    }
}

